<?php
namespace Shopiuu\Model;

use Shopiuu\Http\RequestCore;

class Article extends Model{
    
    public function __construct($accessToken, $endpoint)
    {
        parent::__construct($accessToken, $endpoint);
    }

    /**
     * Create article
     * @param array $params array(
        "name"=> "Sexy Lingerie 005" //文章标题
        "image"=> "//image.example.com/Upload/1/article/2021-05-31/55d8d850af608994.jpg" // 文章图片
        "status"=> "1" //状态， 1 开启 0 关闭
        "sort"=> "0" //排序
        "diy_url"=> "Sexy-Lingerie-003.html" //定义url
        "title"=> "title" //seo 标题
        "keywords"=> "keywords" //seo 关键词
        "descript"=> "descript" //seo 描述
        "details"=> "<p>Sexy Lingerie 005</p>" //文章内容
        "category"=> "News" //文章类目
        "collect_image"=> "1" //是否采集图片
        )
     * @return ResponseCore
     */
    public function add($params)
    {
        $request = $this->getRequest('/openApi/article/add');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Modify article
     * @param array $paramss array(
        "id":"25" //文章id
        "name"=> "Sexy Lingerie 005" //文章标题
        "image"=> "//image.example.com/Upload/1/article/2021-05-31/55d8d850af608994.jpg" // 文章图片
        "status"=> "1" //状态， 1 开启 0 关闭
        "sort"=> "0" //排序
        "diy_url"=> "Sexy-Lingerie-003.html" //定义url
        "title"=> "title" //seo 标题
        "keywords"=> "keywords" //seo 关键词
        "descript"=> "descript" //seo 描述
        "details"=> "<p>Sexy Lingerie 005</p>" //文章内容
        "category"=> "News" //文章类目
        "collect_image"=> "1" //是否采集图片
        )
     * @return ResponseCore
     */
    public function update($params)
    {
        $request = $this->getRequest('/openApi/article/update');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Get articles
     * @param array $params array(
        "pagenum"=> 1 //页码
        "pagesize"=> 20 //每页数量
        "search"=> "keywords" //搜索标题
        "orderfeild"=> "id" //排序字段
        "ordersort"=> "desc" //排序方式
        "start_date"=> "2025-01-01" //开始日期
        "end_date"=> "2025-01-01" //结束日志
     )
     * @return ResponseCore
     */
    public function getList($params)
    {
        $request = $this->getRequest('/openApi/article/lists');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }
    
    /**
     * Delete article
     * @param array $params array("id"=>"25")
     * @return ResponseCore
     */
    public function delete($params)
    {
        $request = $this->getRequest('/openApi/article/delete');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

}